import grails.orm.PagedResultList

class Hotel implements Serializable {
    String name
    String address
    String city
    String state
    String zip
    String country
    BigDecimal price

    static constraints = {
        name(maxSize: 50)
        address(maxSize: 100)
        city(maxSize: 40)
        zip(size: 4..6)
        state(size: 2..10)
        country(size: 2..40)
        price(scale: 2)
    }

    static mapping = {
        table('T_HOTEL')
    }

    public static PagedResultList search(String keyword, Map paginateParams) {
        keyword = '%' + keyword.trim() + '%'

        return Hotel.createCriteria().list(max: paginateParams.max, offset: paginateParams.offset) {
            or {
                ilike('name', keyword)
                ilike('city', keyword)
                ilike('zip', keyword)
                ilike('address', keyword)
            }
        }
    }
}